﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Stardust.ConfigCenterWeb.Code.Entities;
using Loogn.OrmLite;

namespace Stardust.ConfigCenterWeb.Code.Repositories.Impl
{
    public class ServiceContractRepository : IServiceContractRepository
    {
        public List<ServiceContract> GetContractsByNode(long serverNodeId)
        {
            using (var db = DB.Open())
            {
                var list = db.SelectWhere<ServiceContract>("ServerNodeId", serverNodeId);
                return list;
            }
        }

        public bool SaveContracts(long serverNodeId, List<ServiceContract> list)
        {
            using (var db = DB.Open())
            {
                db.DeleteById<ServiceContract>(serverNodeId, "ServerNodeId");
                return db.InsertAll(list);
            }
        }

    }
}